package com.gimi.cloud.jimi.manage.controller.prod;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.Page;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.prod.ProdCatModelDTO;
import com.gimi.cloud.jimi.entity.prod.ProdCatModelEntity;
import com.gimi.cloud.jimi.manage.service.prod.ProdCatModelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 品类模板Controller
 * @auther loongs
 * @date 2017/12/18  16:21
 */
@RestController
@RequestMapping(value = "prodCatModel")
public class ProdCatModelController {
    private static Logger logger = LoggerFactory.getLogger(ProdCatModelController.class);
    private ProdCatModelService prodCatModelService;
    @Autowired
    public ProdCatModelController(ProdCatModelService prodCatModelService) {
        this.prodCatModelService = prodCatModelService;
    }

    @RequestMapping(value = "/getProdCatModelList")
    public void getProdCatModelList(@RequestBody ProdCatModelDTO prodCatModelDTO, HttpServletResponse response) {
        logger.info("获得商品品类模板列表，入参："+prodCatModelDTO);
        Response resp = new Response();
        Page<ProdCatModelDTO> list=prodCatModelService.getProdCatModelList(prodCatModelDTO);
        resp.setRes_data(list);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp),response);
    }
    @RequestMapping(value = "/addProdCatModel")
    public void addProdCatModel(@RequestBody ProdCatModelDTO prodCatModelDTO, HttpServletResponse response) {
        logger.info("添加商品品类模板，入参："+prodCatModelDTO);
        Response resp = new Response();
        ResponseCodeEnum responseCodeEnum= prodCatModelService.addProdCatModel(prodCatModelDTO);
        resp.setResponseCode(responseCodeEnum);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

    @RequestMapping(value = "/gotoEditProdCatModel")
    public void gotoEditProdCatModel(@RequestBody ProdCatModelDTO prodCatModelDTO, HttpServletResponse response) {
        logger.info("转跳到商品品类模板编辑界面，入参："+prodCatModelDTO);
        Response resp = new Response();
        ProdCatModelEntity prodCatModelEntity=prodCatModelService.gotoEditProdCatModel(prodCatModelDTO);
        resp.setRes_data(prodCatModelEntity);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp),response);
    }

    @RequestMapping(value = "/editProdCatModel")
    public void editProdCatModel(@RequestBody ProdCatModelDTO prodCatModelDTO, HttpServletResponse response) {
        logger.info("编辑（修改）商品品类模板，入参："+prodCatModelDTO);
        Response resp = new Response();
        ResponseCodeEnum responseCodeEnum=prodCatModelService.editProdCatModel(prodCatModelDTO);
        resp.setResponseCode(responseCodeEnum);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }


    @RequestMapping(value = "/deleteProdCatModel")
    public void deleteProdCatModel(@RequestBody ProdCatModelDTO prodCatModelDTO, HttpServletResponse response) {
        logger.info("删除商品品类模板，逻辑删除/启用，入参："+prodCatModelDTO);
        Response resp = new Response();
        ResponseCodeEnum responseCodeEnum=prodCatModelService.deleteProdCatModel(prodCatModelDTO);
        resp.setResponseCode(responseCodeEnum);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

    @RequestMapping(value = "/realDeleteProdCatModel")
    public void realDeleteProdCatModel(@RequestBody ProdCatModelDTO prodCatModelDTO, HttpServletResponse response) {
        logger.info("删除商品品类模板，入参："+prodCatModelDTO);
        Response resp = new Response();
        ResponseCodeEnum responseCodeEnum=prodCatModelService.realDeleteProdCatModel(prodCatModelDTO);
        resp.setResponseCode(responseCodeEnum);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
}
